import 'package:flutter/material.dart';

class HouseItem extends StatefulWidget {
  HouseItem({super.key, required this.houseItem});
  // const HouseItem({super.key});
  Map houseItem = {};

  @override
  State<HouseItem> createState() => _HouseItemState();
}

class _HouseItemState extends State<HouseItem> {
  Map house = {};

  @override
  void initState() {
    super.initState();
    house = widget.houseItem;
    // print(house);
  }

  //将第一行的右侧标签结构拆成builder,因为标签有三种状态
  Widget builderTagItem(int status) {
    //定义标签不同状态的样式
    List tagList = [
      {},
      {
        'title': '正在审核',
        'bgcolor': const Color.fromARGB(50, 0, 0, 255),
        'color': const Color.fromARGB(255, 0, 0, 255),
      },
      {
        'title': '审核通过',
        'bgcolor': const Color.fromARGB(50, 0, 255, 0),
        'color': const Color.fromARGB(255, 0, 255, 0),
      },
      {
        'title': '审核失败',
        'bgcolor': const Color.fromARGB(50, 255, 0, 0),
        'color': const Color.fromARGB(255, 255, 0, 0),
      },
    ];

    //第一行
    //结构
    return Container(
      padding: EdgeInsets.only(left: 5, right: 5, top: 2, bottom: 2),
      decoration: BoxDecoration(
        //标签的背景颜色
        color: tagList[status]['bgcolor'],
        borderRadius: BorderRadius.circular(5),
      ),
      child: Text(
        //标签的文字
        tagList[status]['title'],
        //标签的文字样式
        style: TextStyle(color: tagList[status]['color']),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        Navigator.pushNamed(
          context,
          '/house_detail',
          arguments: {'houseId': house['id']},
        );
      },
      child: Container(
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(10),
        ),
        width: MediaQuery.of(context).size.width,
        height: 100,
        padding: EdgeInsets.all(10),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            // //第一行
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Expanded(
                  child: Text(
                    '${house['point']}',
                    style: TextStyle(overflow: TextOverflow.ellipsis),
                  ),
                ),
                // Text('已绑定')
                //标签结构  将房屋的状态传递给结构
                builderTagItem(house['status']),
              ],
            ),
            //第二行
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text('房间号'),
                Text('${house['building']}${house['room']}室'),
              ],
            ),
            //第三行
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [Text('业主'), Text(house['name'])],
            ),
          ],
        ),
      ),
    );
  }
}
